<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@include file="../../util/taglib.jsp" %>
<!DOCTYPE html>
<html lang="en">
<head>
   <title>重新登录页面</title>
</head>
<body>
<div id="editPasswordForm">
        <div class="form-Container">
            <form action="${pageContext.request.contextPath}/adminUser/updatePassword.do"  id="dataForm" class="grayForm" method="post">
             <input type="hidden" name="id" name="id" value="${sessionScope.adminUser.id}"/>
                <table style="width:328px;">
                    <tr>
                        <td  style="width:80px"><label for="userName" style="width:80px">用户名:</label></td>
                        <td  style="line-height:20px;">
                          <input type="hidden" name="userName" id="userName" />
                          ${sessionScope.adminUser.userName}
                        </td>
                    </tr>
                    <tr>
                        <td><label for="oldPassword"  style="width:80px">旧密码:</label></td>
                        <td  style="line-height:20px;"><input type="password" name="oldPassword" id="oldPassword" /></td>
                    </tr>
                    <tr>
                        <td><label for="password1"  style="width:80px">新密码:</label></td>
                        <td  style="line-height:20px;"><input type="password" name="password1" id="password1" /></td>
                    </tr>
                    <tr>
                        <td><label for="password2"  style="width:80px">确认新密码:</label></td>
                        <td  style="line-height:20px;"><input type="password" name="password2" id="password2" /></td>
                    </tr>
                </table>
                <span style="margin-left: 80px;" id="confirmMsg"></span>
            </form>
        </div>
</div>
        <script type="text/javascript">
        var validateForm;
        $(document).ready(function () {
        	//$('#birthday').datepicker();
        	var id = new Number($("#editPasswordForm input[name='id']").val());
        	var rules = {}
        	var messages = {}
        	rules = {
        			oldPassword:{
                		required:true,
                		remote:getBasePath()+"adminUser/checkOldPassword.do"
                	},
                	password1: {  
                	    required: true,
                	    rangelength:[6,18]
                	},
                	password2: {
                	    required: true,  
                	    equalTo: '#password1'
                	}
                };
        		
        		messages = {
        				oldPassword:{
        					required: '请输入旧密码!',
                    		remote:'旧密码输入有误!'
                    	},
    	                password1: {  
    	            	    required: '请输入密码',
    	            	    rangelength:'密码需要6到18位数'
    	            	},
    	            	password2: {
    	            		required:'请输入确认密码',
    	            	    equalTo: '两次输入的密码不一致！'
    	            	}
                    }
        	
        	validateForm = $("#editPasswordForm #dataForm").validate({
                debug:true,
                rules:rules,
                messages:messages
            });
        });
        
        function submitData(){
        	//提交表单进行验证
        	$("#editPasswordForm #dataForm").submit();
            var validateFlag = validateForm.form();
            var actionUrl = $("#editPasswordForm #dataForm").attr("action");
        	var admin_id  = $("#editPasswordForm input[name='id']").val();
        	var oldPassword  = $("#editPasswordForm input[name='oldPassword']").val();
        	var password1  = $("#editPasswordForm input[name='password1']").val();
        	if(validateFlag){
        		$.post(actionUrl,{oldPassword:oldPassword,newPassword:password1},function(data){
        			  console.log(data.code);
        			  if(data.code=="00"){
        				  $.messager.confirm('操作确认',data.msg+',请确认是否继续操作？', function(flag){
        					  if(flag){
        						  $("#actionArea").window("close");
        					  }
        				  });
        			  }else{
        				  $.messager.alert('系统提示',data.msg,'error');
        			  }
        		},"json");
        	}
        }
    </script>
</body>
</html>